/*
 * Filename:    CalculationKpiDAOImpl.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014年10月15日
 */
package com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.intergration.dao.impl;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.dto.CalculationKpiParmDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.dto.KpiBaseFormulaDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.dto.KpiCalculationOtherDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.dto.KpiCalculationResultDTO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.intergration.dao.CalculationKpiDAO;
import com.paic.mhis.hcpms.quota.calculationreport.calculationkpi.util.ContextUtil;
import com.paic.pafa.biz.dao.BaseDAO;

@Component("calculationKpiDAO")
public class CalculationKpiDAOImpl extends BaseDAO implements CalculationKpiDAO {

	@Override
	public List<KpiBaseFormulaDTO> findKpiCodeAndFormualList(String calType) {
		List<KpiBaseFormulaDTO> list = (List<KpiBaseFormulaDTO>) this._queryForList("calculationkpi.queryKpiFormual",
				calType);
		return list;
	}

	@Override
	public List<Map<String, Object>> querySociationData(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.querySociationKpiData", dto);
		return list;
	}

	@Override
	public void insertSociationKpiData(List<KpiCalculationResultDTO> sociationList) {
		this._insert("calculationkpi.insertSociationKpi", sociationList);
	}

	@Override
	public List<Map<String, Object>> queryGradeData(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryGradeKpiData", dto);
		return list;
	}

	@Override
	public void insertGradeKpiData(List<KpiCalculationResultDTO> sociationList) {
		this._insert("calculationkpi.insertGradeKpi", sociationList);
	}

	@Override
	public List<Map<String, Object>> queryCategoryData(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryCategoryKpiData", dto);
		return list;
	}

	@Override
	public List<Map<String, Object>> queryMedicalData(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryMedicalKpiData", dto);
		return list;
	}

	@Override
	public List<Map<String, Object>> queryDepartData(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryDepartKpiData", dto);
		return list;
	}

	@Override
	public List<Map<String, Object>> queryDoctorData(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryDoctorKpiData", dto);
		return list;
	}

	@Override
	public void insertCategoryKpiData(List<KpiCalculationResultDTO> sociationList) {
		this._insert("calculationkpi.insertCategoryKpi", sociationList);

	}

	/* 指标数据表-医院 */
	@Override
	public void insertMedicalKpiData(List<KpiCalculationResultDTO> sociationList) {
		this._insert("calculationkpi.insertMedicalKpi", sociationList);

	}

	/**
	 * 空挂号数 医院 分组查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectMedOrgKghs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectMedOrgKghs", dto);
		return list;
	}

	/**
	 * 空挂号数 医院等级查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectGradeKghs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectGradeKghs", dto);
		return list;
	}

	/**
	 * 空挂号数 医院类型查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectCateKghs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectCateKghs", dto);
		return list;
	}

	/**
	 * 空挂号数 统筹区查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectSociaTionKghs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectSociaTionKghs", dto);
		return list;
	}

	/**
	 * 空挂号数 医院、科室 分组查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDeptKghs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectDeptKghs", dto);
		return list;
	}

	/**
	 * 空挂号数 医院、科室、医生 分组查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDocTtorKghs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectDocTtorKghs", dto);
		return list;
	}

	@Override
	public void insertDepartKpiData(List<KpiCalculationResultDTO> sociationList) {
		this._insert("calculationkpi.insertDepartKpi", sociationList);

	}

	@Override
	public void insertDoctorKpiData(List<KpiCalculationResultDTO> sociationList) {
		this._insert("calculationkpi.insertDoctorKpi", sociationList);

	}

	/**
	 * 查询统筹区维度
	 * 
	 * @param dto
	 * @return
	 */
	@Override
	public List<Map<String, Object>> querySociationKpi(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.querySociationKpi", dto);
		return list;
	}

	/**
	 * 查询等级维度数据表
	 * 
	 * @param dto
	 * @return
	 */
	@Override
	public List<Map<String, Object>> queryGradeKpi(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList("calculationkpi.queryGradeKpi",
				dto);
		return list;
	}

	/**
	 * 查询医院类型维度数据表
	 * 
	 * @param dto
	 * @return
	 */
	@Override
	public List<Map<String, Object>> queryCateKpi(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList("calculationkpi.queryCateKpi",
				dto);
		return list;
	}

	/**
	 * 查询医院维度数据表
	 * 
	 * @param dto
	 * @return
	 */
	@Override
	public List<Map<String, Object>> queryMedorgKpi(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryMedorgKpi", dto);
		return list;
	}

	/**
	 * 查询医院科室维度数据表
	 * 
	 * @param dto
	 * @return
	 */
	@Override
	public List<Map<String, Object>> queryDeptKpi(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList("calculationkpi.queryDeptKpi",
				dto);
		return list;
	}

	/**
	 * 查询医生维度数据表
	 * 
	 * @param dto
	 * @return
	 */
	@Override
	public List<Map<String, Object>> queryDoctorKpi(CalculationKpiParmDTO dto) {
		List<Map<String, Object>> list = (List<Map<String, Object>>) this._queryForList(
				"calculationkpi.queryDoctorKpi", dto);
		return list;
	}

	@Override
	public void calculationKpiRatio(CalculationKpiParmDTO dto) {
		if (ContextUtil.KPI_SOCIATION.equals(dto.getCalculationType())) {
			this._update("calculationkpi.updateSociationKpi", dto);
		} else if (ContextUtil.KPI_GRADE.equals(dto.getCalculationType())) {
			this._update("calculationkpi.updateGradeKpi", dto);
		} else if (ContextUtil.KPI_CATEGORY.equals(dto.getCalculationType())) {
			this._update("calculationkpi.updateCategoryKpi", dto);
		} else if (ContextUtil.KPI_MEDICAL.equals(dto.getCalculationType())) {
			this._update("calculationkpi.updateMedicalKpi", dto);
		} else if (ContextUtil.KPI_DEPART.equals(dto.getCalculationType())) {
			this._update("calculationkpi.updateDepartKpi", dto);
		} else if (ContextUtil.KPI_DOCTOR.equals(dto.getCalculationType())) {
			this._update("calculationkpi.updateDoctorKpi", dto);
		}
	}

	@Override
	public void calculationKpiAdvance(KpiCalculationOtherDTO dto) {
		if (ContextUtil.KPI_SOCIATION.equals(dto.getCalculationType())) {
			this._insert("calculationkpi.insertSociationKpiAdvance", dto);
		} else if (ContextUtil.KPI_GRADE.equals(dto.getCalculationType())) {
			this._insert("calculationkpi.insertGradeKpiAdvance", dto);
		} else if (ContextUtil.KPI_CATEGORY.equals(dto.getCalculationType())) {
			this._insert("calculationkpi.insertCategoryKpiAdvance", dto);
		} else if (ContextUtil.KPI_MEDICAL.equals(dto.getCalculationType())) {
			this._update("calculationkpi.insertMedicalKpiAdvance", dto);
			// } else if
			// (ContextUtil.KPI_DEPART.equals(dto.getCalculationType())) {
			// this._update("calculationkpi.updateDepartKpiAdvance", dto);
			// } else if
			// (ContextUtil.KPI_DOCTOR.equals(dto.getCalculationType())) {
			// this._update("calculationkpi.insertDoctorKpiAdvance", dto);
		}
	}

	@Override
	public int queryMedicalTotalPage(CalculationKpiParmDTO dto) {
		return this._getInt("calculationkpi.queryMedicalTotalPage", dto);
	}

	@Override
	public int queryDepartTotalPage(CalculationKpiParmDTO dto) {
		return this._getInt("calculationkpi.queryDepartTotalPage", dto);
	}

	@Override
	public int queryDoctorTotalPage(CalculationKpiParmDTO dto) {
		return this._getInt("calculationkpi.queryDoctorTotalPage", dto);
	}

	@Override
	public int queryDeptKpiPage(CalculationKpiParmDTO dto) {
		return this._getInt("calculationkpi.queryDeptKpiPage", dto);
	}

	@Override
	public int queryDoctorKpiPage(CalculationKpiParmDTO dto) {
		return this._getInt("calculationkpi.queryDoctorKpiPage", dto);
	}

	/**
	 * 就医人数 医院 分组查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectMedOrgJyrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectMedOrgJyrs", dto);
		return list;
	}

	/**
	 * 就医人数 医院等级查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectGradeJyrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectGradeJyrs", dto);
		return list;
	}

	/**
	 * 就医人数 医院类型查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectCateJyrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectCateJyrs", dto);
		return list;
	}

	/**
	 * 就医人数 统筹区查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectSociaTionJyrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectSociaTionJyrs", dto);
		return list;
	}

	/**
	 * 就医人数 医院、科室 分组查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDeptJyrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectDeptJyrs", dto);
		return list;
	}

	/**
	 * 就医人数 医院、科室、医生 分组查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDocTtorJyrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectDocTtorJyrs", dto);
		return list;
	}

	/**
	 * 医生人数和统计期天数 统筹区查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectSociaTionYsrsTjqrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectSociaTionYsrsTjqrs", dto);
		return list;
	}

	/**
	 * 医生人数和统计期天数 统筹区、医院 查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectMedOrgYsrsTjqrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectMedOrgYsrsTjqrs", dto);
		return list;
	}

	/**
	 * 医生人数和统计期天数 统筹区、科室 查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDeptYsrsTjqrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectDeptYsrsTjqrs", dto);
		return list;
	}

	/**
	 * 医生人数和统计期天数 统筹区、科室、医生 查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDocTtorYsrsTjqrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectDocTtorYsrsTjqrs", dto);
		return list;
	}

	/**
	 * 医生人数和统计期天数 统筹区、医院类型 查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectCateYsrsTjqrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectCateYsrsTjqrs", dto);
		return list;
	}

	/**
	 * 医生人数和统计期天数 统筹区、医院等级 查询
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectGradeYsrsTjqrs(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"calculationkpi.selectGradeYsrsTjqrs", dto);
		return list;
	}

	// =======================================
	/**
	 * 统计医院维度就诊表就诊编号数目
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectMedicalVisitCount(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"dataItem.selectMedicalVisitCount", dto);
		return list;
	}

	/**
	 * 统计医院维度病案表就诊编号数目
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectMedlPageCount(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"dataItem.selectMedlPageCount", dto);
		return list;
	}

	/**
	 * 统计诊断表诊断编号数目
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDiagnoseNoCount(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"dataItem.selectDiagnoseNoCount", dto);
		return list;
	}

	/**
	 * 统计诊断表诊断编号出现在诊断基表的数目
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDiagnoseNoDescCount(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"dataItem.selectDiagnoseNoDescCount", dto);
		return list;
	}

	/**
	 * 统计单据详细表project_code的数量
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectDetailProjectCount(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"dataItem.selectDetailProjectCount", dto);
		return list;
	}

	/**
	 * 统计project_code存在于三大目录的数量
	 * 
	 * @return
	 */
	@Override
	public List<KpiCalculationResultDTO> selectThreeProjectCount(KpiCalculationOtherDTO dto) {
		List<KpiCalculationResultDTO> list = (List<KpiCalculationResultDTO>) this._queryForList(
				"dataItem.selectThreeProjectCount", dto);
		return list;
	}

	// ============================================

}
